﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
//
using Gecko;

namespace browserplayform
{
    public partial class firefoxform : Form
    {
        private readonly string xulrunnerPath = Application.StartupPath + "\\xulrunner";// "D:/Program Files/xulrunner-sdk/bin";//
        private GeckoWebBrowser geckoBrowser;
        public firefoxform()
        {
            InitializeComponent();
            //xulrunner 需要和gecko版本匹配
            try { 
                Xpcom.Initialize(xulrunnerPath);
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
        }

        private void button_go_Click(object sender, EventArgs e)
        {
            try {
                string url_tmp = this.richTextBox_url.Text;
                if (url_tmp != "")
                {
                    this.Controls.Add(geckoBrowser);
                    geckoBrowser.Navigate(url_tmp);
                }
                
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
        }


        private void firefoxform_Load(object sender, EventArgs e)
        {
            try
            {
                geckoBrowser = new GeckoWebBrowser();
                //geckoBrowser.Parent = this;
                geckoBrowser.Dock = DockStyle.Fill;

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
        }
    }
}
